from django.db import models

# Create your models here.
# 会员模型
class Users(models.Model):
    username = models.CharField(max_length=30)
    password = models.CharField(max_length=80)
    phone = models.CharField(max_length=11)
    email = models.CharField(max_length=100,null=True)
    sex = models.IntegerField(null=True)
    age = models.IntegerField(null=True)
    pic = models.CharField(max_length=100)

    # 0 正常  1 禁用       2 删除
    status  =models.IntegerField(default=0)
    addtime = models.DateTimeField(auto_now_add=True)


# 商品分类
class Types(models.Model):
    '''
    name    名称
    pid     等于父类的di
    path    父类id用逗号拼接的产物
    '''

    name = models.CharField(max_length=10)
    pid = models.IntegerField()
    path = models.CharField(max_length=50)




#商品模型(一对多)
class Goods(models.Model):
    # 外键 tid
    tid = models.ForeignKey(to="Types",to_field='id')
    title = models.CharField(max_length=255)
    price  =models.FloatField()
    num = models.IntegerField()
    info = models.TextField()
    pic = models.CharField(max_length=100)
    # 0 新发布   1 热卖  2 下架
    status = models.IntegerField()
    clicknum = models.IntegerField(default=0)
    addtime = models.DateTimeField(auto_now_add=True)








# 地址模型
class Address(models.Model):
    '''
    地址模型通过ForeignKey和用户User构成了   一对多的关系
    
    '''
    # 地址模型uid对应  User用户模型中的  id值
    uid = models.ForeignKey(to='Users',to_field='id')
    # 地址名称
    addressname = models.CharField(max_length=20)
    # 地址
    address = models.CharField(max_length=100)
    # 地址中的电话号码
    addressphone = models.CharField(max_length=11)
    # 是否是默认地址   True 默认地址
    status = models.BooleanField(default=False)





# 订单
class Order(models.Model):
    '''
    通过user  id ;    address   id;  两个id号作为双外键，与用户和地址形成对应关系
    
    '''
    # userid
    uid = models.ForeignKey(to='Users',to_field='id')
    # addressid
    aid = models.ForeignKey(to='Address',to_field='id')
    # 浮点数的价格
    totalprice = models.FloatField()
    # 自动生成点单生成时间
    addtime = models.DateTimeField(auto_now_add=True)
    # 订单状态，默认是0
    status = models.IntegerField(default=0)



# 订单详情
class OrderInfo(models.Model):
    '''
    订单id       外键    对应        订单   Order
    货物列表id   外键    对应        货物    Goods
    '''
    orderid = models.ForeignKey(to="Order", to_field="id")
    goodsid = models.ForeignKey(to="Goods", to_field="id")
    num = models.IntegerField()
    price = models.FloatField()











